//
//  QZRefreshView.h
//  QZRefreshData
//
//  Created by 弘德集团 on 2018/4/12.
//  Copyright © 2018年 弘德集团. All rights reserved.
//

#import <UIKit/UIKit.h>

typedef enum {
    QZRefreshViewStateWillRefresh,
    QZRefreshViewStateRefreshing,
    QZRefreshViewStateNormal
} QZRefreshViewState;

typedef enum {
    QZRefreshViewStyleClassical,
    QZRefreshViewStyleCustom
} QZRefreshViewStyle;
@class QZRefreshView;
typedef void (^RefreshViewOperationBlock)(QZRefreshView *refreshView,CGFloat progress);

@protocol QZRefreshViewAnimationDelegate <NSObject>

- (void)refreshView:(QZRefreshView *)refreshView didBecomeNormalStateWithMovingProgress:(CGFloat)progress;
- (void)refreshView:(QZRefreshView *)refreshView didBecomeWillRefreshStateWithMovingProgress:(CGFloat)progress;
- (void)refreshView:(QZRefreshView *)refreshView didBecomeRefreshingStateWithMovingProgress:(CGFloat)progress;

@end

#define QZRefreshViewObservingKeyPath @"contentOffset"
#define QZKNavigationBarHeight 64
// ———————————————————— 配置 ——————————————
/** 进入刷新状态时的提示文字 */
#define QZRefreshViewRefreshingStateText @"正在加载最新数据，请稍后"
/** 进入即将刷新状态时的提示文字 */
#define QZRefreshViewWillRefreshStateText @"松开即可加载最新数据"

// ———————————————————— 配置 ——————————————

@interface QZRefreshView : UIView

@property (nonatomic, copy) void(^beginRefreshingOperation)();
@property (nonatomic, weak) id beginRefreshingTarget;
@property (nonatomic, assign) SEL beginRefreshingAction;
@property (nonatomic, assign) BOOL isEffectedByNavigationController;
@property (nonatomic, weak) id<QZRefreshViewAnimationDelegate> delegate;

/** 添加观察者 并初始化 */
+ (instancetype)refreshView;
+ (instancetype)refreshViewWithStyle:(QZRefreshViewStyle)refreshViewStyle;

- (void)addToScrollView:(UIScrollView *)scrollView;
- (void)addToScrollView:(UIScrollView *)scrollView isEffectedByNavigationController:(BOOL)effectedByNavigationController;

- (void)addTarget:(id)target refreshAction:(SEL)action;
- (void)endRefreshing;

//支持高度自定义操作的block，需要自定义刷新动画时使用，只需将对应操作加入对应的block即可，注意block的循环引用问题
@property (nonatomic, copy) RefreshViewOperationBlock normalStateOperationBlock;
@property (nonatomic, copy) RefreshViewOperationBlock willRefreshStateoperationBlock;
@property (nonatomic, copy) RefreshViewOperationBlock refreshingStateOperationBlock;





//以下是为子类开放的接口
@property (nonatomic, weak) UIScrollView *scrollView;
@property (nonatomic, assign) QZRefreshViewState refreshState;
@property (nonatomic, copy) NSString *textForNormalState;


/** 子类自定义位置使用 */
@property (nonatomic, assign) UIEdgeInsets scrollViewEdgeinsets;
@property (nonatomic, assign) CGFloat stateIndicatorViewNormalTransformAngle;
@property (nonatomic, assign) CGFloat stateIndicatorViewWillRefreshStateTransformAngle;

//记录原始contenEdgeInsets
@property (nonatomic, assign) UIEdgeInsets originalEdgeInsets;
//加载指示器
@property (nonatomic, weak) UIActivityIndicatorView *activityIndicatorView;
@property (nonatomic, assign) BOOL isManuallyRefreshing;

- (UIEdgeInsets)syntheticalEdgeInsetsWithEdgeInsets:(UIEdgeInsets)edgeInsets;
@end
